<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' xmlns:th='http://www.thymeleaf.org'>

<head>
	<meta charset='UTF-8'/>
	<link rel='stylesheet' type='text/css' href='themes/material/easyui.css'/>
	<link rel='stylesheet' type='text/css' href='themes/icon.css'/>
	<link rel='stylesheet' type='text/css' href='css/style.css'/>
</head>

<body>
	<div id='toolbar' class='top'><ul style='padding-left:5px'><li th:each='btn:${btnlist}'>
		<a href='#' class='easyui-linkbutton' plain='true' onclick='' th:attrappend='onclick=${btn.btnfunc}'>
		<i class='fa fa-' th:attrappend='class=${btn.btnicon}'></i>&nbsp;<span th:text='${btn.btnname}'></span></a></li></ul>
	</div>
	<div id='common-dialog' class='easyui-dialog' modal='true' closed='true' style='display:none;width:325px;height:180px'>
		<div class='easyui-layout' fit='true'>
			<form id='common-form' class='easyui-form' method='post'>
				<input type='hidden' name='id'/>
				<div region='center' border='false'>
				<div class='centerdiv'>
				<table>
					<tr><td><label>角色名称：</label>
					<input class='easyui-textbox' name='rolename' data-options='required:true'/></td></tr>
				</table></div></div>
				<div region='south' border='false' class='southdiv'>
				<a class='easyui-linkbutton' icon='fa fa-check-square-o' href='#' onclick="common_submit(-1,'',0)">保存</a>
				<a class='easyui-linkbutton' icon='fa fa-undo' href='#' onclick='common_reset()'>重置</a>
	</div></form></div></div>
	
	<div id='auth-dialog' class='easyui-dialog' modal='true' title='角色授权' closed='true'
			style='display:none;width:330px;height:260px'>
	<div class='easyui-layout' fit='true'>
		<form id='auth-form' class='easyui-form' method='post' action='/d/saveauth'>
			<input type='hidden' name='id'/>
			<input type='hidden' name='nodes' id='nodes'/>
			<div region='center' border='false'>
			<div class='centerdiv'>
			<table>
				<tr><td><label>角色名称：</label>
				<input class='easyui-textbox' name='rolename' id='authrole' data-options='required:true,editable:false'/></td></tr>
				<tr><td><label>选择权限：</label>
				<select id="pauth"></select></td></tr>
			</table></div></div>
			<div region='south' border='false' class='southdiv'>
			<a class='easyui-linkbutton' icon='fa fa-check-square-o' href='#' onclick="auth_submit(-1,'',0)">保存</a>
			<a class='easyui-linkbutton' icon='fa fa-undo' href='#' onclick='auth_reset()'>重置</a>
	</div></form></div></div>
	<table id='common-table'></table>
	<ul id="spauth"></ul>
	
	<script type='text/javascript' src='jquery.min.js'></script>
	<script type='text/javascript' src='jquery.easyui.min.js'></script>
	<script type='text/javascript' src='js/util.js'></script>
	<script>
		$(function(){
			$('#common-table').datagrid({
				border:false,
				rownumbers: true,
				fitColumns: true,
				fit:true,
				url: '/d/rolelist',
				method: 'post',
				striped : true,
				pagination:true,
				pageSize:25,
				pageList:[25,50],
				singleSelect:true,
				toolbar:'#toolbar',
				columns:[[
					{title:'选择',field:'id',checkbox:true},
					{title:'所属代理',field:'orgname',align:'center',width:100},
					{title:'角色名称',field:'rolename',align:'center',width:100},
					{title:'创建时间',field:'crttm',align:'center',width:100,formatter:formatDate},
				]]
			})
			$('#pauth').combotree({
				url:'/d/getauth',
				prompt:'请选择对应的权限',
				method:'post',
				multiple:true
			})
		});
		function add(){
			common_add('新增','/d/rolesave');
		}
		function edit(){
			common_edit('编辑','/d/roleedit');
		}
		function del(){
			common_delete('/d/roledel',2,'角色被使用，不可删除！',0);
		}
		function auth(){
			$('#auth-dialog').show();
		    var row = $('#common-table').datagrid('getSelected');
		    if (row == null) {
				$.messager.alert('提示', '请先选择,再进行授权！','info');
				return;
			}
		    $('#auth-dialog').dialog('open');
		    $('#auth-form').form('load',row);
		    auth_reset();
		}
		function auth_submit(failcode,fail_info,typecode){
			$('#auth-form').form('submit',{
		    	onSubmit:function(){
		    		$('#nodes').val($('#pauth').combotree('getValues'));
		   	    	$(".panel-tool-close").trigger("click");
		            return $(this).form('enableValidation').form('validate');
		        },
			    success:function(data){
		    		$('#auth-form').form('clear');
		   	    	if(data == 0){
						$.messager.alert('提示', '操作成功！', 'info');
						if(1==typecode)
							$('#common-table').treegrid('reload');
						else
		   	    			$('#common-table').datagrid('reload');
		   	    	}else if(data == failcode)
						$.messager.alert('提示', fail_info, 'info');
					else
						$.messager.alert('提示', '处理失败，请联系管理员！', 'info');
			    }
		    });
		}
		function auth_reset(){
			var row = $('#common-table').datagrid('getSelected');
			$.ajax({
				url : '/d/roleauth',
				type : 'post',
				dataType : 'json',
				data : {
					roleid : row.id
				},
				success : function(data) {
					$('#pauth').combotree('setValues', data);
				},
			});
		}
	</script>
</body>
</html>
